const {
  getLoader
} = require("react-app-rewired");

module.exports = function override(config, env) {
  // 拿到 tsloader
  const tsloader = getLoader(
    config.module.rules,
    rule => String(rule.test) == String(/\.(ts|tsx)$/)
  );
  // 拿到urlloader
  const urlloader = getLoader(
    config.module.rules,
    rule => String(rule.test) == String([/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/])
  )

  //配置产品环境下publicpath
  if (env === 'production') {
    // config.output.publicPath = './'
    urlloader.options = {
      limit: 10000,
      name: 'static/media/[name].[hash:8].[ext]',
    }
  }
  //配置开发环境下publicpath  
  if (env === 'development') {
    config.output.publicPath = '/'
    // 配置json打包
  }

  // 重新设置 options
  tsloader.options = {
    transpileOnly: true,
    getCustomTransformers: () => ({
      before: [
        tsImportPluginFactory({
          libraryName: 'antd',
          libraryDirectory: 'lib',
          style: false
        }, {
            libraryName: 'antd-mobile',
            libraryDirectory: 'lib',
            style: false
          })
      ]
    })
  }
  return config;
};